|
|
|
|
|
|
|
If the user clicks Yes in the message box, you need to delete the record from the database using the Delete method on the Recordset object. Of course, you need to delete the value from the list box also. To do this, store the ListIndex property as an integer value. After the Delete method is invoked, remove the employee data from the list box by invoking the RemoveItem method and passing in the integer variable. |
|
|
|
|
|
|
|
|
Now, you have another problem. The data is still displayed in the controls for the employee just deleted, but theres no value highlighted in the list box. You need to highlight a value in the list box, but which value do you highlight? You could just move to the beginning of the list, or you could move forward to the next value in the list or backward to the previous value in the list. The problem is that if the user is deleting a value in the middle of the list, moving to the first value might position the user somewhere he or she doesnt want to be. Also, if the user deletes the last item in the list, he or she cant move forward, and if the user deletes the first item in the list, he or she cant move backward. This is why you need to call a function that determines where in the list to move. |
|
|
|
|
|
|
|
|
The ListReposition function takes care of figuring out where you should position the list box after a deletion. You simply pass in the list box reference and the current position just deleted, and this function returns a value you can use to set the ListIndex property to a new value. However, if the user deletes the last value in the list box, this function will return -1, in which case youll call Form_Activate. This will be explained in a later section, but lets first take a look at the ListReposition function: |
|
|
|
 |
|
|
|
|
Public Function ListReposition(lstCtrl As Control, _
intIndex As Integer) As Integer
If lstCtrl.ListCount = 0 Then
ListReposition = -1
Else
intIndex = intIndex + 1
If intIndex >= lstCtrl.ListCount - 1 Then
ListReposition = lstCtrl.ListCount - 1
Else
intIndex = intIndex - 1
If intIndex <= 0 Then
ListReposition = 0
Else
ListReposition = intIndex |
|
|
|
|
|